package springbook.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.UpdateProvider;
import springbook.model.BookInfo;
import springbook.model.PageResult;
import springbook.model.RequestPage;

import java.util.List;

@Mapper
public interface BookInfoMapper {
    //1.新增图书
    @Insert("insert into book_info (book_name,author,count,price,publish,status) values (#{bookName}," +
            "#{author},#{count},#{price},#{publish},#{status})")
    Integer insert(BookInfo bookInfo) ;

    @Select("select book_name,author from book_info where book_name=#{bookName} and author=#{author}")
    Boolean queryBookExist(BookInfo bookInfo);

    //查询总的图书数量
    @Select("select count(1) from book_info where status=1")
    Integer count();

    //查询指定书然后放到集合中返回
    @Select("select * from book_info where status!=0  limit #{offset},#{limit}")
    List<BookInfo> getBookInfoByPage(Integer offset, Integer limit);

    @Select("select * from book_info where id = #{bookId}")
    BookInfo queryBookById(Integer bookId);

    //修改
    Integer updateBook(BookInfo bookInfo);

    Integer batchDelete(List<Integer> ids);
}
